﻿using CustomPixelShaderEffect.AttributeUsageFloder;
using CustomPixelShaderEffect.UlitFolder;
using Microsoft.UI;
using Microsoft.UI.Xaml;
using Microsoft.UI.Xaml.Controls;
using Microsoft.UI.Xaml.Controls.Primitives;
using Microsoft.UI.Xaml.Data;
using Microsoft.UI.Xaml.Input;
using Microsoft.UI.Xaml.Media;
using Microsoft.UI.Xaml.Navigation;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Numerics;
using System.Runtime.InteropServices.WindowsRuntime;
using Windows.Foundation;
using Windows.Foundation.Collections;

// To learn more about WinUI, the WinUI project structure,
// and more about our project templates, see: http://aka.ms/winui-project-info.

namespace CustomPixelShaderEffect.views
{
    [PageType("曲线测试")]
    /// <summary>
    /// An empty page that can be used on its own or navigated to within a Frame.
    /// </summary>
    public sealed partial class CurveTest : Page
    {
        public CurveTest()
        {
            this.InitializeComponent();
            Init();
        }
        bool isPressed;
        Point pos;
        int length =100;
        void Init()
        {
            canvas.Draw += (s, e) =>
            {
                Win2dUlit.DrawGridGraphics(e.DrawingSession);
                if (isPressed)
                {
                    var ds = e.DrawingSession;
                    var startX = pos.X;
                    var startY = pos.Y;
                    for(var i = 0; i < length; i++)
                    {
                        var x = startX + i-50;
                        var radius = ((double)i / length) * 2 * Math.PI;
                        var y =Math.Sin(radius)*15 + startY;
                        ds.DrawCircle(new Vector2((float)x, (float)y), 2, Colors.Red);
                    }
                    
                }
            };

            canvas.PointerPressed += (s, e) =>
            {
                isPressed = true;
                pos = e.GetCurrentPoint(canvas).Position;
                canvas.Invalidate();
            };
            canvas.PointerReleased += (s, e) =>
            {
                isPressed = false;
                canvas.Invalidate();
            };
            canvas.PointerMoved += (s, e) =>
            {
                pos = e.GetCurrentPoint(canvas).Position;
                canvas.Invalidate();
            };
        }
    }
}
